home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / _TR_PNUM.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  793b  |  39 lines

  1. /*********
  2. *
  3. *  _TR_PNUM.C
  4. *
  5. *  by Tom Rettig
  6. *  modified by Leonard Zerman
  7. *
  8. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  9. *
  10. *   long _tr_pnum( *char )
  11. *
  12. *   called by _tr_crypt for encrypt() and decrypt(), and by password()
  13. *
  14. *********/
  15.  
  16. #include "trlib.h"
  17.  
  18. long _tr_pnum( s )
  19. char *s;
  20. {
  21.    long ret = 1L;
  22.    int  i;
  23.  
  24.    if ( s[0] && s[1] && s[2] )        /* 3 char minimum password len */
  25.    {
  26.       /* sum the ascii values of each char */
  27.       for ( i = 0; s[i]; i++ )
  28.          ret += (long) (s[i] + i);
  29.  
  30.       /* bit shift ret 1 position to the left until ret exceeds PW_MIN_NUM */
  31.       for (; ret < (PW_MIN_NUM); ret <<= 1 )
  32.            ;
  33.       return( ret );
  34.    }
  35.    else
  36.       return( ERRORNEGL );     /* -1 for error */
  37. }
  38.  
  39.